#include <iostream>

#include "cal.h"

using namespace std;
using namespace cal;

constexpr char RESULT_CHAR = '=';
constexpr char ERROR_CHAR  = '~';

void calculate()
{
    string s;
    Calculator c;
    while (true) 
    try {
        cout << "> ";
        getline(cin, s);
        if (s == "") return;
        auto res = c.calculate(s);
        if (c.quit()) break;
        cout << RESULT_CHAR << " " << res << endl;
    }
    catch (const exception& e) {
        cerr << ERROR_CHAR << " " << e.what() << endl;
    }
}

int main()
try {
    calculate();
    return 0;
}
catch (const exception& e) {
    cerr << e.what() << endl;
}